package net.simflow.swf.analyzer.bgnetwork.stats.opt;

import java.util.Collection;
import java.util.HashMap;
import java.util.HashSet;

import net.simflow.swf.analyzer.bgnetwork.data.BGNetwork;
import net.simflow.swf.analyzer.bgnetwork.data.BGNode;

public class BGNetworkNeighborAnalyzer {

	private static BGNetworkNeighborAnalyzer instance = new BGNetworkNeighborAnalyzer();

	private BGNetworkNeighborAnalyzer() {
	}

	public static BGNetworkNeighborAnalyzer getInstance() {
		return instance;
	}

	public HashMap<BGNode, HashSet<BGNode>> analyzeNetworkFlowNeighbor(
			BGNetwork network) {
		return analyzeNeighbor(network.getFlowMap().values());
	}

	public HashMap<BGNode, HashSet<BGNode>> analyzeNetworkServiceNeighbor(
			BGNetwork network) {
		return analyzeNeighbor(network.getServiceMap().values());
	}

	public HashMap<BGNode, HashSet<BGNode>> analyzeNeighbor(
			Collection<? extends BGNode> partBG) {
		if (partBG == null) {
			return null;
		}

		HashMap<BGNode, HashSet<BGNode>> map = new HashMap<BGNode, HashSet<BGNode>>();

		for (BGNode n : partBG) {
			map.put(n, n.getNeighborSet());
		}

		return map;
	}
}
